package cn.meng.base.handler;

import cn.meng.base.utils.SendMailUtil;
import cn.meng.base.vo.BusinessException;
import cn.meng.base.vo.EmployeeVo;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Map;

/**
 * 邮件过期消息 对应死信队列消费者
 * @author 万梦辉
 */
@Component
public class EmailDeadMessageCustomer {

    @Autowired
    private SendMailUtil sendMailUtil;

    @RabbitListener(queues = {"dead.direct.email.queue"})
    public void handleDeadEmailMessage(Map message) throws BusinessException {
        EmployeeVo employee = (EmployeeVo) message.get("employee");
        File[] files = (File[]) message.get("attachment");
        if(null == files) {
            sendMailUtil.sendMail(employee);
        }else {
            sendMailUtil.sendMailWithAttachment(employee,files);
        }
    }

}
